Swift3: SR-2656: extra releases of dispatch_data_t objects on Linux #177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes an over-release problem in the wrapping overlay that
occurred in callback blocks that take DispatchData structs.
Just going through the glue layer between the Swift and C APIs
should not result in a net change in the reference count of
the dispatch_data_t object that the CDispatch layer is giving
us to hand to the Swift callback block. However, when the
temporary DispatchData struct we created in the wrapping layer
(and its wrapped __DispatchData object) went out of scope at
the end of the callback, the dispatch_data_t was released
by __DispatchData's deinit resulting in an unintended net -1
from the glue code.
We either need to add a compensating retain before entering the
callback block or suppress the release in the deinit. This patch
suppresses the release by adding an internal init that can
create DispatchData's with borrowed dispatch_data_t objects that
are not released on deinitialization.